package cn.cpf.tool.doc;

import cn.cpf.tool.doc.pdf.BookmarkItem;
import cn.cpf.tool.doc.pdf.PDFBoxUtil;
import cn.cpf.tool.doc.pdf.StringUtil;
import com.github.cosycode.common.util.io.FileSystemUtils;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.List;

/**
 * <b>Description : </b>
 *
 * @author CPF
 * Date: 2020/5/7 13:43
 */
@Slf4j
public class MainTest {

    public static final String TAB = "\t";

    public static void main(String[] args) {
        String path = "E:\\res\\FMBS_DEV_BANK\\01-workspace\\01-module1\\99-项目资料\\CFETS参考资料\\开发指引\\新平台本币交易接口开发指南\\第2卷-现券买卖市场V3.3.4.pdf";

        FileSystemUtils.fileDisposeFromDir(new File(path), file -> {
            String filePath = file.getPath();
            String fileName = file.getName();

            List<BookmarkItem> list = PDFBoxUtil.getBookmarkFromFile(filePath);
            StringBuilder sb = new StringBuilder();
            list.stream().forEach(item -> {
                int level = item.getLevel();
                String sName = StringUtil.StringFilter(item.getName(), "[^\\S ]+", " ");
//                sb.append(filePath).append(TAB).append(fileName);
                sb.append(TAB).append(level).append(TAB).append(sName).append(TAB).append(item.getPageNumString(1)).append("\n");
            });
            System.out.println(sb);
            System.out.println();

        }, file -> file.getName().endsWith(".pdf"));

    }
}
